<?php
/**
 * This is the FireFeed Feed form.
 * 
 * @uses       Zend_Form
 * @package    FireFeed
 * @subpackage Form
 */
class Form_Feed extends Zend_Form
{
    /**
     * init() routine called when Zend_Form objects are created.
     * It make sense to define form elements in this method.
     * 
     * @see    http://framework.zend.com/manual/en/zend.form.html
     * @return void
     */ 
    public function init()
    {
        $this->setAction('/feed/addfeed');
        $this->setMethod('POST');
        
        $this->setElementFilters(array('StringTrim'));
        
        $this->setAttrib('class', 'formstyle backgroundForm');
        $this->setAttrib('id', 'formfeed');

                
        // Add Name element
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('name')
             ->setAttrib('class', 'field NoHints')
             ->setAttrib('readonly', 'true')
             ->setRequired(true)
             ->setDecorators(array(
                   array('ViewHelper', array('helper'=>'formText')),
                   array('Label', array('class'=>'gray labelfield')),
                   array('Errors', array('tag' => 'span'))
        ));
        
        // Add URL element
        $url = new Zend_Form_Element_Text('url');
        $url->setLabel('URL:')
             ->setAttrib('class', 'field fieldurl')
             ->setAttrib('onkeyup','checkURL(this);')
             ->setAttrib('onclick','checkURL(this);')
             ->setRequired(true)
             ->setDecorators(array(
                   array('ViewHelper', array('helper'=>'formText')),
                   array('Label', array('class'=>'gray labelfield')),
                   array('Errors', array('tag' => 'span'))
        ));
        
        // Add Description element
        $description = new Zend_Form_Element_Textarea('description');
        $description->setLabel('description')
                    ->setAttrib('readonly', 'true')
		            ->setAttrib('class', 'field fieldtextarea NoHints')
		            ->setDecorators(array(
		                   array('ViewHelper'),
		                   array('Label', array('class'=>'gray labelfield')),
		                   array('Errors', array('tag' => 'span'))
        ));
                 
        $category = new Zend_Form_Element_Select('category');
        $category->setLabel('category')
                 ->setAttrib('id', 'feedcategory')
                 ->setAttrib('class', 'field NoHints')
                 ->setRequired(true)
                 ->setRegisterInArrayValidator(false)
                 ->setDecorators(array(
                       array('ViewHelper'),
                       array('Label', array('separator'=>' ', 'class'=>'gray labelfield')),
                       array('Errors')
                 ));
        
        // Add a submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('save')
               ->setAttrib('class', 'profileSubmit')
               ->setDecorators(array(
                   array('ViewHelper', array('helper'=>'formSubmit'))
        ));
        
        $this->addElements(array(
            $url,
            $name,
            $description,
            $category,
            $submit
        ));
        
        $this->setDecorators(array(
            'FormElements',
            'Form'
        ));
    }
}